#include<iostream>
#include<string>
using namespace std;
typedef long long LL;
const int N = 1e5 + 10;
int n;
int mp[N];
LL f[N];
int main()
{
	cin >> n;
	int ma = 0;
	for (int i = 1; i <= n; i++) {
		int x;
		cin >> x;
		mp[x]++;
		ma = max(ma, x);
	}
	f[1] = mp[1];
	LL ans = f[1];
	for (int i = 2; i <= ma; i++) {
		f[i] = max(f[i - 1], f[i - 2] + 1ll * mp[i] * i);
		ans = max(ans, f[i]);
	}
	cout << ans << endl;
	return 0;
}